<?php
namespace app\run\model;

use think\Model;
use think\Db;
class Banner extends Model{

    public static function zAdd(array $data){
    	$res = Db::name('banner')->insert($data);
    	return $res;
    }


     public static function zIndex(){
    	$res = Db::name('banner')->field('id,name,description')->select();
    	return $res;
    }

      public static function zEdit($id){
    	$res = Db::name('banner')->find($id);
    	return $res;
    }

    public static function zUpdate(array $data){
    	$res = Db::name('banner')->update($data);
    	return $res;
    }

    public static function zDelete($id){
    	$res = Db::name('banner')->delete($id);
    	return $res;
    }

   

    
     public static function add(array $data){
    	$res = Db::name('banner_item')->insert($data);
    	return $res;
    }

     public static function index(){
     	 $res1 = Db::name('banner_item')->alias('a')
		->join('image b','a.img_id=b.id')
		->join('product c','a.key_word= c.id')
		->join('banner d','a.banner_id=d.id')
		->field('a.id,a.type,b.url,c.name,d.name as dname')
		->where('type',1)
		->order('type asc')
		->select()
		->toArray();
        // return $res1;
		 $res2 = Db::name('banner_item')->alias('a')
		->join('image b','a.img_id=b.id')
		->join('theme c','a.key_word= c.id')
		->join('banner d','a.banner_id=d.id')
		->field('a.id,a.type,b.url,c.name,d.name as dname')
		->where('type',2)
		->order('type asc')
		->select()
		->toArray();
		$res3 = array_merge($res1,$res2);
		$res4 = Db::name('banner_item')->alias('a')
		->join('image b','a.img_id=b.id')
		->join('banner d','a.banner_id=d.id')
		->field('a.id,a.key_word as name,a.type,b.url,d.name as dname')
		->where('type',0)
		->order('type asc')
		->select()
		->toArray();
		$res = array_merge($res3,$res4);
    	return $res;
    }

    public static function edit($id){
    	$res = Db::name('banner_item')->where('id',$id)->find();
    	return $res;
    }


    

    public static function up(array $data){
    	$res = Db::name('banner_item')->update($data);
    	return $res;
    }


   public static function del($id){
        $res = Db::name('banner_item')->delete($id);
        return $res;
    }
}